package com.xbjtech.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.xbjtech.mapper.OrderMapper;
import com.xbjtech.mapper.YzmMapper;
import com.xbjtech.model.Order;
import com.xbjtech.model.OrderExample;
import com.xbjtech.model.Yzm;
import com.xbjtech.service.OrderService;

@Service
public class OrderServiceImpl implements OrderService {

	@Autowired
	OrderMapper orderMapper;
	
	@Autowired
	YzmMapper yzmMapper;
	
	@Override
	public List<Order> list(OrderExample example, Integer page, Integer rows) {
		PageHelper.startPage(page, rows);
		return orderMapper.selectByExampleWithBLOBs(example);
	}

	@Override
	public void insertOrder(Order order) throws Exception {
		orderMapper.insertSelective(order);
	}
	
	@Override
	public void updateOrder(Order order) throws Exception {
		orderMapper.updateByPrimaryKeySelective(order);
	}

	@Override
	public void deleteOrderById(Long id) throws Exception {
		orderMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void save(List<Order> orders) {
		for (Order o : orders) {
			orderMapper.insert(o);
		}
		throw new RuntimeException();
	}
	@Override
	public Order selectOrderById(Long id) {
		return orderMapper.selectByPrimaryKey(id);
	}

	/* (non-Javadoc)
	 * @see com.xbjtech.service.OrderService#pd(com.xbjtech.model.Order, com.xbjtech.model.Yzm)
	 */
	@Override
	public void pd(Order order, Yzm yzm) {
		orderMapper.updateByPrimaryKey(order);
		yzmMapper.updateYzm(yzm);
	}

	@Override
	public void hx(Order order, Yzm yzm) {
		orderMapper.updateByPrimaryKey(order);
		yzmMapper.updateYzm(yzm);
	}

}
